package controller

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

type JsonStruct struct {
	Code  int         `json:"code"`  //返回的是 200 400 404 500...
	Msg   interface{} `json:"msg"`   //返回的信息
	Data  interface{} `json:"data"`  //返回的数据
	Count int64       `json:"count"` //返回的数据总数
}

type JsonErrorStruct struct {
	Code int         `json:"code"` //返回的是 200 400 404 500...
	Msg  interface{} `json:"msg"`  //返回的信息
}

func ReturnSuccess(c *gin.Context, code int, msg interface{}, data interface{}, count int64) {
	json := &JsonStruct{
		Code:  code,
		Msg:   msg,
		Data:  data,
		Count: count,
	}
	c.JSON(http.StatusOK, json)
}

func ReturnError(c *gin.Context, code int, msg interface{}) {
	json := &JsonErrorStruct{
		Code: code,
		Msg:  msg,
	}
	c.JSON(200, json)
}
